import axios from 'axios'
import { useStore } from '@/store/index'
const store = useStore()
const service = axios.create({
    baseURL: 'http://120.77.156.205:8808',
    timeout: 60000,
    withCredentials: true,
    // crossDomain: true
})


service.interceptors.request.use(
    function (config) {
        //配置token
        let token = localStorage.getItem('token')
        //如果token存在，放到请求的头部
        if (token) {
            config.headers = {
                ...config.headers,
                token: token
            }
        }
        return config
    },
    function (error) {
        console.log(error)
        return Promise.reject(error)
    }
)

service.interceptors.response.use(
    function (response) {
        return response
    },
    function (error) {
        console.log(error)
        return Promise.reject(error)
    }
)

export default service

